08. Exploring the Sim
Exploring the Quadrotor Simulator
For the lab component of this module, you will be using ROS to interface with a quadrotor in DroneSim, Udacity’s Unity-based simulation environment.
DroneSim provides a comprehensive set of tools which will greatly assist you as you begin to tune and troubleshoot your quadrotor’s flight controllers. In the following sections we you will learn everything you need to know to hit the ground running!
Updating ROS Settings File
Before you launch DroneSim for the first time, you should take a moment to be sure that it’s properly configured to communicate with the ROS Master on your Linux VM. To do this, you will inspect the ros_settings.txt
configuration file. While it is possible to launch and interact with DroneSim without updating this file, you won’t be able to explore and use most of the features that you’ll be introduced to here.
Note: On most systems not using the virtual machine, updating ros_settings.txt
should not be necessary.
The ros_settings.txt
file can be found in the the following locations:
For Windows
DroneSim_Win_Data/ros_settings.txt
For MacOS
DroneSim_OSX.app/Contents/ros_settings.txt
Warning: do not use the default Mac text editor as it will cause trouble with the characters. If you have trouble connecting to ROS on VM, try to change the trailing double quotes on the vm-ip
line to proper double quotes.
Below is an example configuration:
{
"vm-ip" : "192.168.30.111",
"vm-port" : 11311,
"vm-override" : false,
"host-ip": "0.0.0.0",
"host-override" : false
}
** vm-ip **
The IP address of your Linux virtual machine. You can determine this IP by entering echo $(hostname -I)
in a terminal of your choice in the supplied Udacity virtual machine. Be aware that the ip address of your VM can change. If you are experiencing problems, be sure to check that the VM's ip matches that of which you have in ros_settings.txt
vm-port
The ROS Master port number on the virtual machine. While port 11311 is the default, you can verify by looking at the console output of the roscore
command, where it is printed as part of the ROS_MASTER_URI (e.g
ROS_MASTER_URI=http://hostname:11311/
).
vm-override
This controls whether the above info is used or not. If you are running the simulator from outside of the virtual machine (which you should be) It should be set to true.
host-ip
The IP address associated with the host machine. This setting is disregarded if host-override
is false.
host-override
This should be set to true, if and only if you are updating the host-ip
setting.
Launching the Simulator
To launch the simulator, simply double-click the DroneSim executable. If you wish to change the resolution of the simulator do the following. For Windows: Hold the crtl key upon simulator boot. For Mac: Hold the option key upon boot. For Linux: Add -show-screen-selector
as an argument when launching the sim from a terminal.
Key Command and GUI Overview
Below, you will be introduced some of the basic GUI functionality that is available in the simulator. In additions to the explanations below, the simulator provides a legend of all of the key mappings used by the simulator. to bring up this legend hit “L”.
Moving Around With The Keyboard
To fly the quad around the simulator without using your controller, simply click the “Input On” button in the lower left-hand corner. To get a list of the key commands that will allow you to fly around with local input turned on.
Note: When local input is enabled, force commands from ROS will be ignored. Make sure that it’s not enabled while you are testing your flight controllers!
Changing Viewpoints
To change the position of the scene camera with respect to the quad, you can use number keys on the keyboard. If you’d like to change the distance between the scene camera and the quad, you can use the scrollwheel on your mouse. To reset the viewpoint back to the original view, simply right click in the camera viewport.
Topics
Below is a list of topics published/subscribed to by the simulator. For more detailed information about the associated message types, simply use the command $ rosmsg show
. To obtain this list of topics via the command line, you can use the command $ rostopic list
.
** /quad_rotor/cmd_force
(Subscribed) **
Through this topic forces and torques can be passed to the quadrotor. All force units are Newtons, and all torque units are Newton meters. All forces and torques comply with ROS unit and coordinate conventions (REP-103) and will be applied to or about the corresponding body frame axis.
Note: cmd_force
commands are “latched” by the simulator. This means that a commanded force or torque command will continually be applied until the a new command has been received by the simulator.
/quad_rotor/cmd_vel
(Subscribed)
Through this topic it is possible to set velocities on the quad’s body frame. This topic is provided for debugging purposes only.
** /quad_rotor/image
(Published) **
Depth images from the quad’s depth camera are published to this topic. You won’t be using this topic for the Controls Lab.
** /quad_rotor/imu
(Published) **
The quadrotor’s IMU provides an estimate of linear accelerations, angular velocities, and the quad body’s orientation. We won’t be using this topic in this controls lab, and will instead use the perfect position and orientations that are provided by the pose topic.
** /quad_rotor/pose
(Published) **
This topic provides the “ground-truth” position and orientation of the quad, expressed in terms of the inertial (world) frame. In a real quadrotor, the ground truth pose would not be available for our use, but might instead be estimated using a number of sensors, such as a GPS, and IMU, and a barometric pressure sensor.
Services
** /quad_rotor/camera_distance
**
Sets the distance of the camera from quadrotor body frame. Units are in meters.
** /quad_rotor/camera_pose_type
**
Sets the camera pose. Following is a list of the acceptable values.
0: Orthogonal to the inertial frame's YZ plane, facing the positive X direction.
1: Orthogonal to the inertial frame's XZ plane, facing the positive Y direction.
2: Orthogonal to the inertial frame's XY plane, facing the negative Z direction.
3: Perspective view, facing the quad's body frame origin from the -X,-Y, +Z quadrant.
** /quad_rotor/get_path
**
Get’s the path from the simulator
** /quad_rotor/set_path
**
Loads a path into the simulator.